import { apiPostRealNameVerifiaction } from '@/pages/_server/_api/Mine/apiPostRealNameVerifiaction';
import Taro from '@tarojs/taro';
import { useCallback } from 'react';

export const useAuthenticationContent = () => {
    /**聚焦触发 */
    const handelFocus = useCallback((event) => {
        event.target.parentNode.style.border = '2px solid #FF8828';
    }, []);
    /**失焦触发 */
    const handelBlur = useCallback((event) => {
        event.target.parentNode.style.border = '2px solid #E5E5E5';
    }, []);
    /**点击按钮保存触发 */
    const handleSave = useCallback(async (form) => {
        let isValidatePass = await form.validateFields(['name', ['identify']]).then(
            (val) => {
                console.log('表单验证通过', val);
                return true;
            },
            (val) => {
                console.log('表单验证失败', val);
                return false;
            }
        );
        if (!isValidatePass) return;
        let formData = form.getFieldsValue();
        let res = await apiPostRealNameVerifiaction({ id: formData.identify, realName: formData.name });
        if (!res) return;
        await Taro.showToast({
            title: res.message,
            icon: 'none',
        });
        Taro.navigateTo({
            url: 'pages/Mine/Mine',
        });
    }, []);

    return {
        handelFocus,
        handelBlur,
        handleSave,
    };
};
